package ico.domain;

import ico.enums.City;
import java.util.Arrays;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;

/**
 * @author ISJINHAO
 */
@Component
public class User implements InitializingBean, DisposableBean {

    private Long id;

    private String name;

    private City city;

    private City[] workCities;

    private List<City> lifeCities;

    private Resource configFileLocation;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setConfigFileLocation(Resource configFileLocation) {
        this.configFileLocation = configFileLocation;
    }

    public City getCity() {
        return city;
    }

    public void setCity(City city) {
        this.city = city;
    }

    public City[] getWorkCities() {
        return workCities;
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", city=" + city +
                ", workCities=" + Arrays.toString(workCities) +
                ", lifeCities=" + lifeCities +
                ", configFileLocation=" + configFileLocation +
                '}';
    }

    public void setWorkCities(City[] workCities) {
        this.workCities = workCities;
    }

    public List<City> getLifeCities() {
        return lifeCities;
    }

    public void setLifeCities(List<City> lifeCities) {
        this.lifeCities = lifeCities;
    }

    public static User createUser() {
        User user = new User();
        user.setId(1l);
        user.setName("isjinhao");
        return user;
    }

    @PostConstruct
    public void init() {
        System.out.println("@PostConstruct : User 初始化中 ... ");
    }

    @PreDestroy
    public void preDestroy() {
        System.out.println("@PreDestroy : User 销毁中...");
    }

    public void initUser() {
        System.out.println("@Bean(initMethod = \"initUser\") : User 初始化中 ... ");
    }

    public void destroyUser() {
        System.out.println("@Bean(destroyMethod = \"destroyUser\") : User 销毁中...");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("InitializingBean接口 : User 初始化中 ... ");
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("DisposableBean接口 : User 销毁中...");
    }

    @Override
    protected void finalize() throws Throwable {
        System.out.println("User 对象正在被回收" );
    }

}
